<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>待发货订单</title>
    <script th:src="@{/layui/layui.js}" type="text/javascript"></script>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
<body>
<div style="margin: 20px">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <input type="hidden" id="orderId" th:value="${m.id}">
            <label class="layui-form-label">选择框</label>
            <div class="layui-input-block">
                <select id="company" lay-verify="required">
                    <option value=""></option>
                    <option value="邮政">邮政</option>
                    <option value="韵达">韵达</option>
                    <option value="顺丰">顺丰</option>
                    <option value="京东">京东</option>
                    <option value="中通">中通</option>
                    <option value="极兔">极兔</option>
                    <option value="申通">申通</option>
                    <option value="圆通">圆通</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">物流单号</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" id="number" autocomplete="off" />
            </div>
        </div>
    </form>
</div>

<div class="layui-form-item" style="display: none;">
    <div class="layui-input-block">
        <a class="layui-btn" lay-submit="" lay-filter="submitBtn" id="submitBtn">提交</a>
        <a class="layui-btn" data-method="cancelBtn" id="cancelBtn">取消</a>
    </div>
</div>
<script>
    var $;
    layui.use(['table','form','layer','jquery'],function() {
        var table = layui.table, form = layui.form, layer = layui.layer;
        $ = layui.jquery;
        var orderId = $('#orderId').val();

        var active = {
            dialog:function (data) {
                var company = $('#company').val();
                var number = $('#number').val();
                var dataForm = data.field;
                dataForm.company = company;
                dataForm.number = number;
                $.ajax({
                    type:'post',
                    url:'/cc/order/addOne',
                    data:dataForm,
                    dataType:'json',
                    success:function(result){
                        active.send(orderId,result);
                    }
                })
            },
               send:function (id,cid) {
                    $.ajax({
                        type:'post',
                        url:'/order/oc/update',
                        data:{
                            id: id,
                            status: 2,
                            courier: cid
                        },
                        dataType: 'json',
                        success:function (result) {
                            layer.msg(result.msg);
                            let index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);//关闭父页面窗口
                        }
                    })
                }
        }

        form.on('submit(submitBtn)',function(data){
            active.dialog(data);
        })
    });

    function btnSubmit(){
        $('#submitBtn').click();
    }
    function btnCancel() {
        $('#cancelBtn').click();
    }
</script>
</body>
</html>